package com.longyiqun.cm.mapper;

import com.longyiqun.cm.domain.SceneEntity;
import com.longyiqun.cm.domain.TestCaseEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;
@Mapper
@Controller
public interface SceneMapper {

    @Select("${sql}")
    List<SceneEntity> FindAllScene(@Param("sql")String sql);

    @Select("${sql}")
    String geturl(@Param("sql")String sql);

    @Select("${sql}")
    SceneEntity findOne(@Param("sql")String sql);

    @Insert("insert into test_scene_entity (name,script,leader,eStatus,sceneExplain,module,count,env) values (#{name},#{script},#{leader},#{eStatus},#{sceneExplain},#{module},#{count},#{env})")
    int addScene(SceneEntity sceneEntity);


    @Insert("insert into test_api_entity (sceneID,caseID,url,runOrder,shouldbe,body,loginName,name,method,module,chinese) values(#{sceneID},#{caseID},#{url},#{runOrder},#{shouldbe},#{body},#{loginName},#{name},#{method},#{module},#{chinese})")
    int addAPI(SceneEntity sceneEntity);


    @Select("select * from test_api_entity where sceneID =#{sceneID} order by runOrder ASC")
    List<SceneEntity> FindAllAPI(@Param("sceneID")String sceneID);

    @Update("update test_scene_entity set name =#{name},script=#{script},leader=#{leader},eStatus=#{eStatus},sceneExplain=#{sceneExplain},module=#{module} where sceneID=#{sceneID}")
    int upadteScene(SceneEntity sceneEntity);

    @Update("update test_api_entity set url=#{url},runOrder=#{runOrder},shouldbe=#{shouldbe},body=#{body},loginName=#{loginName},env=#{env} where relationID = #{relationID}")
    int upadteAPI(SceneEntity sceneEntity);

    @Update("${sql}")
    int updateSql(@Param("sql")String sql);

    @Select("select * from test_case_entity where url = #{url} limit 1")
    TestCaseEntity findAPIDetail(@Param("url")String url);


    @Select("${sql}")
    List<TestCaseEntity> APISelect(@Param("sql")String sql);

    @Select("${sql}")
    String  GetsceneID(@Param("sql")String sql);

    @Delete("${sql}")
    int del(@Param("sql") String sql);

    @Select("select script from test_scene_entity where sceneID = #{sceneID}")
    String getscript(@Param("sceneID")String sceneID);
}
